package com.just.just_bankreputationsystem.Intercepter;

import com.just.just_bankreputationsystem.Model.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 请求处理前进行权限拦截
 */
public class AuthorIntercepter extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //login强求放行
        if (request.getRequestURI().endsWith("/login")||request.getRequestURI().endsWith(".css")||request.getRequestURI().endsWith(".js")||request.getRequestURI().endsWith(".png")){
            return true;
        }
        User user=(User) request.getSession().getAttribute("user");
        if(user==null){
            //没有登陆
            response.sendRedirect(request.getContextPath()+"/user/login");
            return false;
        }else {
            return true;
        }
    }
}
